package org.brisling.medical.service;

import java.util.List;

import org.brisling.common.SysConfig;
import org.brisling.medical.domain.BaseMedical;
import org.brisling.medical.domain.MedicalRecipel;
import org.brisling.medical.queryService.QueryBasemedicalService;
import org.brisling.sysman.domain.VOJobUser;
import org.brisling.sysman.queryService.QueryPermissionService;
import org.brisling.sysman.service.base.BaseSysmanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/BaseMedical")
/**
 * 抗菌药物使用率CUD服務service
 * @Author : jackson wang
 * @Date   : 2015年6月8日 下午4:18:01
 * @version: 1.0
 */
public class BaseMedicalService extends BaseSysmanService<BaseMedical>{
	
	@Autowired
	private RecipelService qryService;
	
	@Autowired
	private QueryBasemedicalService qryBaseMedicalService;
	
	@Autowired
	private QueryPermissionService qryPermissionService;
	
	/**
	 * 自动插入
	 * @param BaseMedical
	 */

	public List<BaseMedical> autoInsertData(){
		List<BaseMedical>  lists=qryBaseMedicalService.getBaseMedicalAbnormal();
		String Bizcode = qryPermissionService.getBizFlowConfig("recipel").getFullBizcode();
		String flowid = qryPermissionService.getBizFlowConfig("recipel").getFlowid();
		
		if(lists!=null){
			for(BaseMedical a:lists){
				//System.out.println("\n__________________________________________________________________________________" + a.getDept_name() + "_________________________________________");
				if(!a.getData_type().equals("2")){
					//System.out.println("\nbad0000000000000000000000000000000000000000000000");
					continue;
				}
				//System.out.println("here, that have one");
				MedicalRecipel sendObj = new MedicalRecipel();
				sendObj.setId(null);
				sendObj.setInquiry_item("用药异常");
				sendObj.setInquiry_item_sub("基药比例");
				sendObj.setDoct_depart_name(a.getDept_name());
				//sendObj.setDeptName(a.getDept_name());
				//sendObj.setDeptid(a.getDept_code());
				sendObj.setDoct_depart_code(a.getDept_code().toString());
				sendObj.setInquiry_date(new java.sql.Date(new java.util.Date().getTime()));
				sendObj.setPatient_type(a.getPatient_type());
				List<VOJobUser> jobUsr = SysConfig.getJobUserByDept("20", a.getDept_code().toString());
				sendObj.setDoct_name(jobUsr.get(0).getDoct_name());
				sendObj.setDoct_id(jobUsr.get(0).getDoct_code().toString());
				//sendObj.setPatient_id(a.getPatient_no());
				//sendObj.setPatient_name(a.getPatient_name());
				sendObj.setInquiry_item_code("6");
				sendObj.setInquiry_item_subcode("13");
				String reson = "";
				if(a.getPatient_type().equals("2")){
					reson += "住院基本药品价格占比不足， 请核实";
				}
				else{
					reson += "门急诊基本药品价格占比不足， 请核实";
				}
				sendObj.setInquiry_reason(reson);
				sendObj.setFlowid(flowid);
				sendObj.setFullBizcode(Bizcode);
				//设置异常实体信息
				String id =SysConfig.getConfig("inquiryUserId");
				qryService.completeTask(id, sendObj);
			}
		}
		return lists;
	}
	

}
